AC_INIT([tc], [3.0])
AM_INIT_AUTOMAKE

SHELL=/bin/sh

dnl Disable cache files:
dnl This is controversial, but I am convinced this is the right way to go,
dnl at least by default.  Otherwise there are too many surprises.
define([AC_CACHE_LOAD], )dnl
define([AC_CACHE_SAVE], )dnl
define([AC_CACHE_VAL], [
$2
])dnl

AC_PROG_INSTALL
AC_PROG_CC

dnl
dnl Apparently, if you run a shell window in Emacs, it sets the EMACS
dnl environment variable to 't'.  Lets undo the damage.
dnl
if test "${EMACS}" = "t"; then
   EMACS=""
fi

AC_ARG_WITH(emacs,
changequote(<<, >>)dnl
  --with-emacs=EMACS      specify the full path name of Emacs [EMACS=emacs],
changequote([, ])dnl
 [ if test "${withval}" = "yes"; then EMACS=emacs; else EMACS=${withval}; fi ])
AM_PATH_LISPDIR
lispdir=${lispdir}/tc
AC_ARG_WITH(lispdir,  dnl
  --with-lispdir=DIR      Emacs Lisp files in DIR,
lispdir=${withval})

dnl AC_ARG_WITH(makeinfo,dnl
dnl   --with-makeinfo         Specify how to build info files,
dnl  [ MAKEINFO="$withval" ])
dnl  AC_ARG_ENABLE(site-install,   --enable-site-install     Perform a sitewide installation, [ DOTEMACS='$(prefix)/share/emacs/site-lisp/default.el' ], [ DOTEMACS=`( cd ; pwd)`/.emacs ])

dnl AC_CHECK_PROG(TEXI2HTML, texi2html, texi2html, echo Cannot create html version of)
dnl AC_CHECK_PROGS(EMACS, emacs xemacs meadow mule nemacs, emacs)
AC_CHECK_PROG(MAKEINFO, makeinfo, makeinfo, \$(EMACS) -q -no-site-file -batch -l texinfmt -f batch-texinfo-format)
AC_CHECK_PROG(INSTALLINFO, install-info, install-info, true)

dnl AC_EMACS_PACKAGES
dnl AC_PATH_LISPDIR

AC_EMACS_VERSION

dnl if test "${MAKEINFO}" = "no"; then
dnl    MAKEINFO='$(EMACS) -q -no-site-file -batch -l texinfmt -f batch-texinfo-format'
dnl fi

dnl if test "${TEXI2HTML}" = "texi2html"; then
dnl    TEXI2HTML_FLAGS="-menu -glossary -number -split_node"
dnl fi

AC_SUBST(PACKAGE)
AC_SUBST(VERSION)
AC_SUBST(EMACS_PACKAGE_DIR)
AC_SUBST(MAKEINFO)
AC_SUBST(EMACS)
AC_SUBST(INSTALL)
AC_SUBST(INSTALLINFO)
INSTALL_SCRIPT=$INSTALL
AC_SUBST(INSTALL_SCRIPT)
AC_SUBST(DOTEMACS)
AC_SUBST(TEXI2HTML)
AC_SUBST(TEXI2HTML_FLAGS)
pkgdatadir=$datadir/tc
AC_SUBST(pkgdatadir)

AC_OUTPUT(Makefile
	  etc/Makefile
	  doc/Makefile
          kinput2/Makefile
	  lisp/Makefile
	  lisp/tc-pre-base
	  mazegaki/Makefile
	  bushu-util/Makefile
	  skkinput3/Makefile
	  skkinput3/tcinput
         )

AC_MSG_RESULT(" ")
AC_MSG_RESULT("Sucessfully configured Emacs/tc2")
if test -n "$EMACS_PACKAGE_DIR"; then
   AC_MSG_RESULT("Using package root:                ${EMACS_PACKAGE_DIR}")
fi
AC_MSG_RESULT("Emacs/tc2 will be compiled with:    ${EMACS}")
AC_MSG_RESULT("Lisp files will be installed into:    ${lispdir}")
AC_MSG_RESULT(" ")
AC_MSG_RESULT("To finish building Emacs/tc2 type \'make\' now.")
AC_MSG_RESULT("To install Emacs/tc2 type \'make install\'.")
